package com.zhilingshenghuo.app.zhly

import android.annotation.SuppressLint
import android.content.Intent
import android.os.CountDownTimer
import com.zhilingshenghuo.app.zhly.utils.ShareUtil
import com.zhilingshenghuo.app.zhly.view.BaseActivity
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.activity_luck_draw.*
import kotlinx.android.synthetic.main.activity_welcome.*

class WelcomeActivity : BaseActivity() {

    override fun getLayoutResId(): Int {
        return R.layout.activity_welcome
    }

    @SuppressLint("SetTextI18n")
    override fun initView() {
        super.initView()
        Glide.with(this).asGif().load(R.drawable.gif_loading_activity_welcome).into(ivGifLoading)

        if (!intent.getStringExtra("token").isNullOrEmpty()) {
            ShareUtil.getInstance().save(ShareUtil.ACCESS_TOKEN, intent.getStringExtra("token"))
            val phone = intent.getStringExtra("phone")
            ShareUtil.getInstance().save(ShareUtil.PHONE, phone)
        }

        val backOpen = ShareUtil.getInstance().get(ShareUtil.BACKGROUND_OPEN)
        val musicOpen = ShareUtil.getInstance().get(ShareUtil.MUSIC_OPEN)
        if (backOpen.isNullOrEmpty()) {
            ShareUtil.getInstance().save(ShareUtil.BACKGROUND_OPEN, "1")
        }
        if (musicOpen.isNullOrEmpty()) {
            ShareUtil.getInstance().save(ShareUtil.MUSIC_OPEN, "1")
        }
        val time = object : CountDownTimer(4000, 1000) {
            override fun onTick(millisUntilFinished: Long) {

            }

            override fun onFinish() {
                val intent = Intent(this@WelcomeActivity, HomeActivity::class.java)
                startActivity(intent)
                finish()
            }
        }.start()
        val versionName: String = packageManager
            .getPackageInfo(packageName, 0).versionName
        tvVersionName.text = "v$versionName"
    }

    override fun onClick() {

    }

}